package com.hspedu.newData.dmsxl.树.二叉搜索树的操作;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-19 
 * @Version: 1.0
 */

public class LC1038从二叉搜索树到更大和树 {

    int pre = 0;
    public TreeNode bstToGst(TreeNode root) {

        if (root == null){
            return null;
        }

        bstToGst(root.right);
        pre += root.val;
        root.val = pre;
        bstToGst(root.left);
        return root;
    }
}
